import React, { useState, useEffect } from 'react'
import { View, Text, Image, Swiper, SwiperItem, Button, Radio } from '@tarojs/components'
import "taro-ui/dist/style/components/float-layout.scss";
import { AtFloatLayout } from "taro-ui"
import { useDidShow } from '@tarojs/taro'
import { toast } from '@/utils/utils'
import { wechatAuth } from "@/utils/utils";
import { fetchWechatAuth } from "@/server/login";
import Router from '@/utils/router'
import './index.scss'
const wechatLogin = (props) => {
    const {
        visible = {},
        onClose,
        userInfo = {}
    } = props
    const { show = false } = visible
    const [check, setCheck] = useState(false)

    useEffect(() => {
        if (!show) {
            setCheck(false)
        }
    }, [show])
    const { organizationId } = userInfo
    const goOrganization = () => {
        if (!check) {
            toast('请阅读并同意隐私协议和服务协议后登录')
        } else if (!organizationId) {
            Router('selectOrganization')
        } else {
            wechatAuth((e) => {
                fetchWechatAuth({ code: e, })
                    .then((val) => {
                        // console.log(launchOptions);
                        console.log(val)

                    })
                    .catch((e) => {

                    });
            })
        }
    }
    return <AtFloatLayout onClose={onClose} isOpened={show}>
        <View className='wechatLogin_body_box'>
            <Image className='wechatLogin_body_img' src={'https://gygj-wechat.oss-cn-hangzhou.aliyuncs.com/wechatImage/loginQt.png'}></Image>
            <View onClick={goOrganization} className=''>
                <Image className='wechatLogin_body_btn' src={'https://gygj-wechat.oss-cn-hangzhou.aliyuncs.com/wechatImage/FrameBtn.png'}></Image>
            </View>
            <View className='wechatLogin_rule wechatLogin_rule_color1'>
                <View onClick={() => setCheck(!check)} className={check ? 'wechatLogin_radioSelect' : 'wechatLogin_radio_icon'}></View>   我已阅读并同意 <Text className='wechatLogin_rule_color2'>《学管家服务协议》</Text  >和 <Text className='wechatLogin_rule_color2'> 《隐私政策》</Text>
            </View>
        </View>
    </AtFloatLayout>
}
export default wechatLogin